import 'package:flutter/material.dart';

import '../models/gEntity.dart';
import '../common/flatPanel.dart';
import '../entry.dart';
import '../utils/screw.dart';

class GEntityView extends StatefulWidget {
  @override
  _GEntityViewState createState() => _GEntityViewState();
}

class _GEntityViewState extends State<GEntityView> {
  final entry = Entry.GEntity;
  final baseUrl = Entry.BaseUrl + Entry.GEntity;
  final dio = Screw.dioInstance;
  var _items = <GEntity>[];
  var _topics = <String>[];

  _getTopics() async {
    var data = await Screw.getList(baseUrl + '/topics', entry, 'topics');
    setState(() {
      _topics = data.cast<String>();
    });
  }

  _getTopic(String topic) async {
    var data = await Screw.getList(baseUrl + '/topic/' + topic, entry, topic);
    setState(() {
      _items = GEntity.genFromList(data);
    });
  }

  @override
  Widget build(BuildContext context) {
    return FlatScaffold(
      entry,
      child: ListView.separated(
          itemCount: _items.length,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text('${_items[index].label}'),
              subtitle: Text('${_items[index].body}'),
            );
          },
          separatorBuilder: (context, i) => Divider()),
    );
  }
}
